home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Apache 1.0 / src / httpd.h < prev    next >
Text File  |  1995-12-04  |  14KB  |  447 lines

  1.  
  2. /* ====================================================================
  3.  * Copyright (c) 1995 The Apache Group.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer. 
  11.  *
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in
  14.  *    the documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  * 3. All advertising materials mentioning features or use of this
  18.  *    software must display the following acknowledgment:
  19.  *    "This product includes software developed by the Apache Group
  20.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  21.  *
  22.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  23.  *    endorse or promote products derived from this software without
  24.  *    prior written permission.
  25.  *
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *
  52.  */
  53.  
  54.  
  55. /*
  56.  * httpd.h: header for simple (ha! not anymore) http daemon
  57.  */
  58.  
  59. /* Headers in which EVERYONE has an interest... */
  60.  
  61. #include "conf.h"
  62. #include "alloc.h"
  63.  
  64. /* ----------------------------- config dir ------------------------------ */
  65.  
  66. /* Define this to be the default server home dir. Anything later in this
  67.  * file with a relative pathname will have this added.
  68.  */
  69. #define HTTPD_ROOT "/usr/local/etc/httpd"
  70.  
  71. /* Root of server */
  72. #define DOCUMENT_LOCATION "/usr/local/etc/httpd/htdocs"
  73.  
  74. /* Max. number of dynamically loaded modules */
  75. #define DYNAMIC_MODULE_LIMIT 64
  76.  
  77. /* Default administrator's address */
  78. #define DEFAULT_ADMIN "[no address given]"
  79.  
  80. /* 
  81.  * --------- You shouldn't have to edit anything below this line ----------
  82.  *
  83.  * Any modifications to any defaults not defined above should be done in the 
  84.  * respective config. file. 
  85.  *
  86.  */
  87.  
  88.  
  89. /* -------------- Port number for server running standalone --------------- */
  90.  
  91. #define DEFAULT_PORT 80
  92.  
  93. /* --------- Default user name and group name running standalone ---------- */
  94. /* --- These may be specified as numbers by placing a # before a number --- */
  95.  
  96. #define DEFAULT_USER "#-1"
  97. #define DEFAULT_GROUP "#-1"
  98.  
  99. /* The name of the log files */
  100. #define DEFAULT_XFERLOG "logs/access_log"
  101. #define DEFAULT_ERRORLOG "logs/error_log"
  102. #define DEFAULT_PIDLOG "logs/httpd.pid"
  103.  
  104. /* Define this to be what your HTML directory content files are called */
  105. #define DEFAULT_INDEX "index.html"
  106.  
  107. /* Define this to 1 if you want fancy indexing, 0 otherwise */
  108. #define DEFAULT_INDEXING 0
  109.  
  110. /* Define this to be what type you'd like returned for files with unknown */
  111. /* suffixes */
  112. #define DEFAULT_TYPE "text/html"
  113.  
  114. /* Define this to be what your per-directory security files are called */
  115. #define DEFAULT_ACCESS_FNAME ".htaccess"
  116.  
  117. /* The name of the server config file */
  118. #define SERVER_CONFIG_FILE "conf/httpd.conf"
  119.  
  120. /* The name of the document config file */
  121. #define RESOURCE_CONFIG_FILE "conf/srm.conf"
  122.  
  123. /* The name of the MIME types file */
  124. #define TYPES_CONFIG_FILE "conf/mime.types"
  125.  
  126. /* The name of the access file */
  127. #define ACCESS_CONFIG_FILE "conf/access.conf"
  128.  
  129. /* Whether we should enable rfc931 identity checking */
  130. #define DEFAULT_RFC931 0
  131. /* The default directory in user's home dir */
  132. #define DEFAULT_USER_DIR "public_html"
  133.  
  134. /* The default path for CGI scripts if none is currently set */
  135. #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
  136.  
  137. /* The path to the Bourne shell, for parsed docs */
  138. #define SHELL_PATH "/bin/sh"
  139.  
  140. /* The default string lengths */
  141. #define MAX_STRING_LEN HUGE_STRING_LEN
  142. #define HUGE_STRING_LEN 8192
  143.  
  144. /* The timeout for waiting for messages */
  145. #define DEFAULT_TIMEOUT 1200
  146.  
  147. /* The size of the server's internal read-write buffers */
  148. #define IOBUFSIZE 8192
  149.  
  150. /* The number of header lines we will accept from a client */
  151. #define MAX_HEADERS 200
  152.  
  153. /* RFC 1123 format for date - this is what HTTP/1.0 wants */
  154. #define HTTP_TIME_FORMAT "%a, %d %b %Y %T GMT"
  155.  
  156. /* Number of servers to spawn off by default --- also, if fewer than
  157.  * this free when the caretaker checks, it will spawn more.
  158.  */
  159. #define DEFAULT_START_DAEMON 5
  160.  
  161. /* Maximum number of *free* server processes --- more than this, and
  162.  * they will die off.
  163.  */
  164.  
  165. #define DEFAULT_MAX_FREE_DAEMON 10
  166.  
  167. /* Minimum --- fewer than this, and more will be created */
  168.  
  169. #define DEFAULT_MIN_FREE_DAEMON 5
  170.  
  171. /* Limit on the total --- clients will be locked out if more servers than
  172.  * this are needed.  It is intended solely to keep the server from crashing
  173.  * when things get out of hand.
  174.  */
  175.  
  176. #define DEFAULT_SERVER_LIMIT 150
  177.  
  178. /* Number of requests to try to handle in a single process.  If <= 0,
  179.  * the children don't die off.  That's the default here, since I'm still
  180.  * interested in finding and stanching leaks.
  181.  */
  182.  
  183. #define DEFAULT_MAX_REQUESTS_PER_CHILD 0
  184.  
  185. /* ------------------------------ error types ------------------------------ */
  186.  
  187. #define SERVER_VERSION "Apache/1.0.0"
  188. #define SERVER_PROTOCOL "HTTP/1.0"
  189. #define SERVER_SUPPORT "http://www.apache.org/"
  190.  
  191. #define DECLINED -1        /* Module declines to handle */
  192. #define OK 0            /* Module has handled this stage. */
  193.  
  194. #define DOCUMENT_FOLLOWS 200
  195. #define REDIRECT 302
  196. #define USE_LOCAL_COPY 304
  197. #define BAD_REQUEST 400
  198. #define AUTH_REQUIRED 401
  199. #define FORBIDDEN 403
  200. #define NOT_FOUND 404
  201. #define SERVER_ERROR 500
  202. #define NOT_IMPLEMENTED 501
  203. #define SERVICE_UNAVAILABLE 503
  204. #define RESPONSE_CODES 10
  205.  
  206. #define METHODS 5
  207. #define M_GET 0
  208. #define M_PUT 1
  209. #define M_POST 2
  210. #define M_DELETE 3
  211. #define M_INVALID 4
  212.  
  213. #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
  214. #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
  215. #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
  216. #define MAP_FILE_MAGIC_TYPE "application/x-type-map"
  217. #define ASIS_MAGIC_TYPE "httpd/send-as-is"
  218. #define DIR_MAGIC_TYPE "httpd/unix-directory"
  219.  
  220. /* Just in case your linefeed isn't the one the other end is expecting. */
  221. #define LF 10
  222. #define CR 13
  223.  
  224. /* Things which may vary per file-lookup WITHIN a request ---
  225.  * e.g., state of MIME config.  Basically, the name of an object, info
  226.  * about the object, and any other info we may ahve which may need to
  227.  * change as we go poking around looking for it (e.g., overridden by
  228.  * .htaccess files).
  229.  *
  230.  * Note how the default state of almost all these things is properly
  231.  * zero, so that allocating it with pcalloc does the right thing without
  232.  * a whole lot of hairy initialization... so long as we are willing to
  233.  * make the (fairly) portable assumption that the bit pattern of a NULL
  234.  * pointer is, in fact, zero.
  235.  */
  236.  
  237. typedef struct conn_rec conn_rec;
  238. typedef struct server_rec server_rec;
  239. typedef struct request_rec request_rec;
  240.  
  241. struct request_rec {
  242.  
  243.   pool *pool;
  244.   conn_rec *connection;
  245.   server_rec *server;
  246.  
  247.   request_rec *next;        /* If we wind up getting redirected,
  248.                  * pointer to the request we redirected to.
  249.                  */
  250.   request_rec *prev;        /* If this is an internal redirect,
  251.                  * pointer to where we redirected *from*.
  252.                  */
  253.   
  254.   request_rec *main;        /* If this is a sub_request (see request.h) 
  255.                  * pointer back to the main request.
  256.                  */
  257.  
  258.   /* Info about the request itself... we begin with stuff that only
  259.    * protocol.c should ever touch...
  260.    */
  261.   
  262.   char *the_request;        /* First line of request, so we can log it */
  263.   int assbackwards;        /* HTTP/0.9, "simple" request */
  264.   int header_only;        /* HEAD request, as opposed to GET */
  265.   char *protocol;        /* Protocol, as given to us, or HTTP/0.9 */
  266.   
  267.   char *status_line;        /* Status line, if set by script */
  268.   int status;            /* In any case */
  269.   
  270.   /* Request method, two ways; also, protocol, etc..  Outside of protocol.c,
  271.    * look, but don't touch.
  272.    */
  273.   
  274.   char *method;            /* GET, HEAD, POST, etc. */
  275.   int method_number;        /* M_GET, M_POST, etc. */
  276.  
  277.   /* int header_bytes_sent; */
  278.   int bytes_sent;        /* body --- not headers */
  279.   
  280.   /* MIME header environments, in and out.  Also, an array containing
  281.    * environment variables to be passed to subprocesses, so people can
  282.    * write modules to add to that environment.
  283.    *
  284.    * The difference between headers_out and err_headers_out is that the
  285.    * latter are printed even on error, and persist across internal redirects
  286.    * (so the headers printed for ErrorDocument handlers will have them).
  287.    *
  288.    * The 'notes' table is for notes from one module to another, with no
  289.    * other set purpose in mind...
  290.    */
  291.   
  292.   table *headers_in;
  293.   table *headers_out;
  294.   table *err_headers_out;
  295.   table *subprocess_env;
  296.   table *notes;
  297.  
  298.   char *content_type;        /* Break these out --- we dispatch on 'em */
  299.   char *content_encoding;
  300.   char *content_language;
  301.   
  302.   int no_cache;
  303.   
  304.   /* What object is being requested (either directly, or via include
  305.    * or content-negotiation mapping).
  306.    */
  307.   
  308.   char *uri;
  309.   char *filename;
  310.   char *path_info;
  311.   char *args;            /* QUERY_ARGS, if any */
  312.   struct stat finfo;        /* ST_MODE set to zero if no such file */
  313.   
  314.   /* Various other config info which may change with .htaccess files
  315.    * These are config vectors, with one void* pointer for each module
  316.    * (the thing pointed to being the module's business).
  317.    */
  318.   
  319.   void *per_dir_config;        /* Options set in config files, etc. */
  320.   void *request_config;        /* Notes on *this* request */
  321.   
  322. };
  323.  
  324.  
  325. /* Things which are per connection
  326.  */
  327.  
  328. struct conn_rec {
  329.   
  330.   pool *pool;
  331.   server_rec *server;
  332.   
  333.   /* Information about the connection itself */
  334.   
  335.   FILE *client;            /* Connetion to the guy */
  336.   FILE *request_in;        /* Connection from the guy */
  337.   int aborted;            /* Are we still talking? */
  338.   
  339.   /* Who is the client? */
  340.   
  341.   char *remote_ip;        /* Client's IP address */
  342.   char *remote_host;        /* Client's DNS name, if known */
  343.   char *remote_name;        /* Host ID --- same as remote_host, if known;
  344.                  * otherwise same as remote_ip.
  345.                  */
  346.   char *remote_logname;        /* Only ever set if doing_rfc931 */
  347.   
  348.   char *user;            /* If an authentication check was made,
  349.                  * this gets set to the user name.  We assume
  350.                  * that there's only one user per connection(!)
  351.                  */
  352.   char *auth_type;        /* Ditto. */
  353. };
  354.  
  355. /* Per-vhost config... */
  356.  
  357. struct server_rec {
  358.  
  359.   server_rec *next;
  360.   
  361.   /* Full locations of server config info */
  362.   
  363.   char *srm_confname;
  364.   char *access_confname;
  365.   
  366.   /* Contact information */
  367.   
  368.   char *server_admin;
  369.   char *server_hostname;
  370.   
  371.   /* Log files --- note that transfer log is now in the modules... */
  372.   
  373.   char *error_fname;
  374.   FILE *error_log;
  375.   
  376.   /* Module-specific configuration for server, and defaults... */
  377.  
  378.   void *module_config;        /* Config vector containing pointers to
  379.                  * modules' per-server config structures.
  380.                  */
  381.   void *lookup_defaults;    /* MIME type info, etc., before we start
  382.                  * checking per-directory info.
  383.                  */
  384.   /* Transaction handling */
  385.  
  386.   short port;
  387.   struct in_addr host_addr;    /* Specific address, if "virtual" server */
  388.   int timeout;            /* Timeout, in seconds, before we give up */
  389.   int do_rfc931;        /* See if client is advertising a username? */
  390.   
  391. };
  392.  
  393. /* Prototypes for utilities... util.c.
  394.  */
  395.  
  396. /* Time */
  397.  
  398. struct tm *get_gmtoff(long *tz);
  399. char *get_time();
  400. char *ht_time (pool *p, time_t t, char *fmt, int gmt);     
  401. char *gm_timestr_822(pool *p, time_t t);
  402.      
  403. /* String handling */     
  404.      
  405. char *getword(pool *p, char **line, char stop);
  406. char *getword_conf (pool *p, char **line);      
  407.      
  408. int is_url(char *u);
  409. extern int unescape_url(char *url);
  410. void no2slash(char *name);
  411. void getparents(char *name);
  412. char *escape_path_segment(pool *p, const char *s);
  413. char *os_escape_path(pool *p,const char *path);
  414. char *escape_uri (pool *p, char *s);
  415. char *construct_url (pool *p, char *path, server_rec *s);     
  416. char *escape_shell_cmd (pool *p, char *s);
  417.      
  418. int count_dirs(char *path);
  419. char *make_dirstr(pool *a, char *s, int n);
  420. char *make_full_path(pool *a, char *dir, char *f);
  421.      
  422. int is_matchexp(char *str);
  423. int strcmp_match(char *str, char *exp);
  424. char *uudecode (pool *, char *);
  425.  
  426. void str_tolower (char *);
  427. int ind (const char *, char);    /* Sigh... */
  428. int rind (const char *, char);     
  429.  
  430. int cfg_getline(char *s, int n, FILE *f);
  431.      
  432. /* Misc system hackery */
  433.      
  434. uid_t uname2id(char *name);
  435. gid_t gname2id(char *name);
  436. int is_directory(char *name);
  437. int can_exec(struct stat *);     
  438. void chdir_file(char *file);
  439.      
  440. char *get_local_host(pool *);
  441. struct in_addr get_local_addr (int sd);
  442. unsigned long get_virthost_addr (char *hostname, int wild_allowed);
  443. void get_remote_host(conn_rec *conn);
  444. int get_portnum(int sd);
  445.      
  446.  
  447.